<template>
	<view class="content" @tap.stop="$refs.uniselect.close()">
        <u-navbar bgColor="#fff" :safeAreaInsetTop="true" :placeholder="true" :fixed="true"
            @leftClick="back" title="考勤管理" rightIcon="search" @rightClick="rightClick">
        </u-navbar>
        <uni-select class="uniselect" :style="{top:systemInfo.headerH+'px'}"
            ref="uniselect" bgColor="#fff" :selectData="selectData" @select="select">
        </uni-select>
        <view style="height:74rpx"></view>

        <!-- 内容 -->
        <view class="uni-area">
            <!-- 考勤概览 -->
            <view class="u-m-t-30 uni-shadow">
                <text class="font-bold">考勤概览</text>
                <view class="u-m-t-40 u-flex u-row-between">
                    <view v-for="(item,index) in overviews" :key="index" class="u-flex u-flex-col">
                        <text class="u-m-b-14 u-font-24 uni-dec-color">{{item.title}}</text>
                        <text class="u-font-42 font-bold uni-higt-color">{{item.value}}</text>
                    </view>
                </view>
            </view>

            <!-- 考勤列表 -->
            <view class="u-m-t-50 u-font-32 font-bold">考勤列表</view>
            <uni-item-attendance class="u-m-t-30" v-for="(tem,ind) in page.list" :key="ind" :listItem="tem"/>

            <!-- 返回顶部 -->
            <u-back-top :scroll-top="page.scrollTop" @tap="toTop"></u-back-top>
            <!-- 加载更多 -->
            <u-loadmore :status="page.status" />
        </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                // 设备信息
                systemInfo: uni.getStorageSync('systemInfo'),
                // 下拉选择数据
				selectData:[
                    { label: "属地", list: [], show: false, type: "districtId", value: '' },
                    { label: "项目类型", list: [], show: false, type: "xmtype", value: '' },
                ],
                // 筛选参数
                prameter:{
                    districtId: '', // 属地
                    xmtype: '', // 项目类型
                },
                // 考勤概览
                overviews:[
                    { field:'staffs', title:'实名制总人数', value:'100' },
                    { field:'istaffs', title:'进场总人数', value:'100' },
                    { field:'atdStaffs', title:'今日考勤数', value:'100' },
                    { field:'atdRate', title:'今日考勤率', value:'88%' },
                ],
                // 分页相关参数
                paging:{
                    pageNum: 1,
                    pageSize: this.$config.pageSize,
                },
                page:{
                    scrollTop: 0,
                    status: 'loading',
                    total: 0,
                    list: [], // 列表
                },
			}
		},

        onPageScroll(e) {
            this.page.scrollTop = e.scrollTop;
        },
        onReachBottom(){
            if( this.page.list.length < this.page.total ){
                this.paging.pageNum += 1
                this.page.status = 'loading'
                this.getKqList()
            }else{
                this.page.status = 'nomore'
            }
        },

		onLoad() {
            // 属地
            this.$tools.getNationFn(this,{},res=>{
                this.selectData.splice(0,1,res)
                this.prameter.districtId = res.value
            })
            // 项目类型
            this.$tools.getProTypeFn(this,res=>{
                this.selectData.splice(1,1,res)
                this.prameter.xmtype = res.value
            })
            // 考勤概览
            this.getKqStaffsStatistics()
            // 考勤列表
            this.getKqList()
        },


		methods: {
            // 返回
            back(){
                uni.navigateBack()
            },
            // 搜索
            rightClick(){
                uni.navigateTo({ url: '/pages/common/search?type=attendance' })
            },

            // 考勤概览
            getKqStaffsStatistics(){
                uni.showLoading({ title:'考勤概览加载中' })
                // console.log('考勤概览-参数',this.prameter)
                this.$request(this,this.$apis.kqStaffsStatistics,this.prameter).then(res=>{
                    // console.log('考勤概览',res)
                    this.overviews.map((v,i)=>{
                        v.value = res[v.field]
                    })
                }).then()
            },
            // 考勤列表
            getKqList(){
                const prameter = Object.assign(this.prameter,this.paging)
                // console.log('考勤列表参数',prameter)
                this.$request(this,this.$apis.kqList,prameter).then(res=>{
                    // console.log('考勤列表',res)
                    this.page.total = res.total
                    if( res.total && res.total != 0 ){
                        this.status = 'loadmore'
                        res.data.map((v,i)=>{
                            this.page.list.push(v)
                        })
                    }else{
                        this.page.status = 'nomore'
                        uni.$u.toast('暂未查询到更多考勤列表相关数据')
                    }
                }).then()
            },
            

            // 下拉选择
            select(e){
                this.prameter[e.type] = e.value
                // 考勤概览
                this.getKqStaffsStatistics()
                // 考勤列表
                this.paging.pageNum = 1,
                this.page.list = []
                this.toTop()
                this.getKqList()
            },

            // 回到顶部
            toTop(){
                uni.pageScrollTo({ scrollTop: 0, duration: 300 })
            }
		}
	}
</script>

<style scoped lang="scss">
    .content{
        .uniselect{
            width: 100%;
            position: fixed !important;
            left: 0;
        }
    }
</style>
